﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Phoenix.Backend
{
    public partial class CorpInfo : System.Web.UI.Page
    {
        Phoenix.AppCode.Entities.CorpInfo corpinfo = new Phoenix.AppCode.Entities.CorpInfo();
        string success = "<div class='alert_success'><p><img src='../Content/Backend/images/icon_accept.png' alt='success' class='mid_align'/>" + "Cập nhật thông tin thành công." + "</p></div>";
        string error = "<div class='alert_error'><p><img src='../Content/Backend/images/icon_error.png' alt='error' class='mid_align'/>" + "Máy chủ đang bận. Vui lòng thử lại." + "</p></div><br class='clear'/>";
        string info = "<div class='alert_info'><p><img src='../Content/Backend/images/icon_info.png' alt='info' class='mid_align'/>" + "Thông tin chưa được cập nhật." + "</p></div><br  class='clear'/>";
        //protected void Page_PreInit(object sender, EventArgs e)
        //{
        //    if (Session["Theme"].ToString() != "")
        //    {
        //        Page.Theme = Session["Theme"].ToString();
        //    }
        //}
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {
                    DataTable dt_Edit = Phoenix.AppCode.Bussiness.CorpInfoService.CorpInfoList();
                    txtCorpName_vi.Text = dt_Edit.Rows[0]["CorpName"].ToString();
                    txtCorpName_en.Text = dt_Edit.Rows[1]["CorpName"].ToString();
                    txtAddress_vi.Text = dt_Edit.Rows[0]["Address"].ToString();
                    txtAddress_en.Text = dt_Edit.Rows[1]["Address"].ToString();
                    txtPhone.Text = dt_Edit.Rows[0]["Phone"].ToString();
                    txtFax.Text = dt_Edit.Rows[0]["Fax"].ToString();
                    txtEmail.Text = dt_Edit.Rows[0]["Email"].ToString();
                }
                catch (FormatException)
                {
                    Response.Redirect("Error.aspx");
                }
            }
        }
        
        protected void btnEdit_Click(object sender, EventArgs e)
        {
            corpinfo = Phoenix.AppCode.Bussiness.CorpInfoService.GetCorpInfo();

            corpinfo.CorpName_vi = txtCorpName_vi.Text;
            corpinfo.CorpName_en = txtCorpName_en.Text;
            corpinfo.Address_vi = txtAddress_vi.Text;
            corpinfo.Address_en = txtAddress_en.Text;
            corpinfo.Phone = txtPhone.Text;
            corpinfo.Fax = txtFax.Text;
            corpinfo.Email = txtEmail.Text;

            Phoenix.AppCode.Bussiness.CorpInfoService.Edit(corpinfo);
            lblWarningE.Text = success;
            //Response.Redirect("CorpInfo.aspx");

        }
        protected void btnCancelE_Click(object sender, EventArgs e)
        {
            DataTable dt_Edit = Phoenix.AppCode.Bussiness.CorpInfoService.CorpInfoList();
            txtCorpName_vi.Text = dt_Edit.Rows[0]["CorpName"].ToString();
            txtCorpName_en.Text = dt_Edit.Rows[1]["CorpName"].ToString();
            txtAddress_vi.Text = dt_Edit.Rows[0]["Address"].ToString();
            txtAddress_en.Text = dt_Edit.Rows[1]["Address"].ToString();
            txtPhone.Text = dt_Edit.Rows[0]["Phone"].ToString();
            txtFax.Text = dt_Edit.Rows[0]["Fax"].ToString();
            txtEmail.Text = dt_Edit.Rows[0]["Email"].ToString();
            lblWarningE.Text = info;
        }
    }
}